package com.jason.www.pubsub.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;

/**
 * @author ybd
 * @date 17-10-20.
 *
 * 自定义事件发布器
 */
@Component
public class CustomEventPublisher implements ApplicationContextAware {
	private static final Logger LOGGER = LoggerFactory.getLogger(CustomEventPublisher.class);
	private static ApplicationContext applicationContext;

	public static void publish(ApplicationEvent event) {
		applicationContext.publishEvent(event);
		LOGGER.info("success publish an event -> " + event.toString());
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		CustomEventPublisher.applicationContext = applicationContext;
	}
}
